/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import mint.mvc.annotation.BaseMapping;
import mint.mvc.annotation.Mapping;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Baojia;
import pojo.CarCountry;
import pojo.CarPinpai;
import pojo.CarType;
import pojo.User;
import util.HibernateUtil;
import util.JSONRenderer;

@BaseMapping("/report")
public class ReportAction {

    /**
     * "/index" 和 "/"都可以访问到此方法
     *
     * @return
     */
    @Mapping(urls = {"/get"}, method = "get")
    public JSONRenderer login(String username, String password, HttpServletRequest hs) {
        Session ss = HibernateUtil.getSessionFactory().openSession();
        String hql = "from CarCountry";
        Query query = ss.createQuery(hql);
        List<CarCountry> list = query.list();
        Map map = new HashMap();
        for (int i = 0; i < list.size(); i++) {

           CarCountry obj = (CarCountry) list.get(i);
            map.put( obj.getId(),obj.getCountryname());
        }
        
        
        String hql_CarPinpai = "from CarPinpai";
        Query query_CarPinpai = ss.createQuery(hql_CarPinpai);
        List<CarPinpai> list_CarPinpai = query_CarPinpai.list();
        Map map_CarPinpai = new HashMap();
        for (int i = 0; i < list_CarPinpai.size(); i++) {

           CarPinpai obj = (CarPinpai) list_CarPinpai.get(i);
            map_CarPinpai.put( obj.getId(),obj.getPinpai());
        }
        
        //String ssString ="";
        String hql_CarType = "from CarType";
        Query query_CarType = ss.createQuery(hql_CarType);
        List<CarType> list_CarType = query_CarType.list();
//        Map map_CarPinpai = new HashMap();
        List list01=new ArrayList();
        for (int i = 0; i < list_CarType.size(); i++) {

           CarType obj = (CarType) list_CarType.get(i);
           //	id	car_type	pinpai_id	baojia_URL_input
          String str[] = {obj.getCarType(),map_CarPinpai.get(obj.getPinpaiId()).toString(),obj.getBaojiaUrlInput()};
          list01.add(str);
//ssString=ssString+obj.getCarType()+"---"+map_CarPinpai.get(obj.getPinpaiId()).toString()+"<br>";
        }
        
        ss.close();
         return new JSONRenderer(list01);
    }
    
    @Mapping(urls = {"/baojia"}, method = "get")
    public JSONRenderer baojia(String username, String password, HttpServletRequest hs) {
        Session ss = HibernateUtil.getSessionFactory().openSession();
      
        String hql_CarType = "from Baojia";
        Query query_CarType = ss.createQuery(hql_CarType);
        List<Baojia> list_CarType = query_CarType.list();
//      
        
        ss.close();
         return new JSONRenderer(list_CarType);
    }
}
